sampler2D sprite;
float factor = 1; // means full desaturation.

float4 PixelShaderFunction(float2 pixel : TEXCOORD0) : COLOR0
{	
	float4 color;
	float4 graycolor;

	color = tex2D(sprite, pixel);
	graycolor = color;

	// convert RGB to BW. This method is better than calculating the average of the three color components, because
	// it takes in consideration the responsiveness of the human eye to the colors.
	graycolor.rgb = graycolor.r * 0.3 + graycolor.g * 0.59 + graycolor.b * 0.11;
	// mix the original color with it's BW version.
	color = color * (1 - factor) + graycolor * factor; 


	return color;
}

technique Technique1
{
	pass Pass1
	{
		PixelShader = compile ps_2_0 PixelShaderFunction();
	}
}
